package com.activenetwork.smlite.snippet;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import com.activenetwork.util.DateUtil;
import com.google.common.collect.Lists;

public class RfpDateCalculator {
	// calendar format must be "MM/dd/yyyy"
	private List<RfpDay> rfpDays = new ArrayList<RfpDay>();
	
	public RfpDateCalculator(String rfpStartDate, String rfpEndDate, int preceding, int following) throws ParseException{
		DateUtil du = new DateUtil();
		int origin = DateUtil.calculateBetween(rfpEndDate, rfpStartDate, "MM/dd/yyyy")+1;
		int totalDay = preceding + origin + following;
		String firstDay = du.stringOffset(rfpStartDate, preceding, false);
		for(int i=1; i<=totalDay; i++){
			RfpDay rfpDay = new RfpDay();
			rfpDay.setRowIndex(i);
			rfpDay.setDate(du.stringOffset(firstDay, i-1, true));
			if(i<=preceding){
				rfpDay.setCategory("pre");			
			}else if(i<=(preceding + origin)){
				rfpDay.setCategory("origin");
			}else{
				rfpDay.setCategory("post");
			}
			rfpDays.add(rfpDay);
		}
	}
	
	public int rfpLength(){
		return rfpDays.size();
	}
	
	public int rfpLength(String category){
		int count = 0;
		for(RfpDay day : rfpDays){
			if(day.getCategory().equals(category)){
				count++;
			}
		}
		return count;
	}	
	
	public List<RfpDay> getRfpDays(String Category){
		List<RfpDay> list = Lists.newArrayList();
		for(RfpDay day : rfpDays){
			if(day.getCategory().equals(Category)){
				list.add(day);
			}
		}
		return list;
	}
	
	public void printList(){
		for(RfpDay day : rfpDays){
			System.out.println(day.getDate() + " - " + day.getCategory());
		}
	}

}
